package chat_udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UdpReceiver {
    public static void main(String[] args) throws Exception {
        DatagramSocket socket=new DatagramSocket(6666);
        while(true) {
            //准备接受包裹
            byte[] buffer = new byte[1024];
            DatagramPacket dp = new DatagramPacket(buffer, 0, buffer.length);
            socket.receive(dp);
            //断开连接，
            byte[] data=dp.getData();
            String recevieData=new String(data,0,data.length);

            System.out.println(recevieData);
                if (recevieData.equals("bye")) {
                    break;
                }
            }
        socket.close();
        }
    }

